package com.fengmi.bloom;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class RedissonDemo {
    public static void main(String[] args) {

        //配置redis
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.25.130:6379")
        .setPassword("123456");

        //实例化redisson客户端
        RedissonClient redissonClient = Redisson.create(config);


        //实例化bloomfilter
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter("bitkey");

        bloomFilter.tryInit(1000000,0.001);


        //存数据
        bloomFilter.add("1");
        bloomFilter.add("2");
        bloomFilter.add("3");
        bloomFilter.add("baidu");
        bloomFilter.add("4");


        //判断元素是否存在
        boolean exists = bloomFilter.contains("xx");
        System.out.println("exists = " + exists);

    }
}
